package com.hui.controller;

import com.hui.model.Admin;
import com.hui.model.People;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * TODO: json和xml的数据绑定
 *
 * @author chenth
 * @create 2018-07-30 23:50
 **/
@Controller
public class JsonAndXMLController {

    /**
     * json数据绑定
     * @param people
     * @return
     *     {
            "sex":"man",
            "address":"guangzhou",
            "user":{
                "name":"zhangsan",
                "age":"500"
                }
            }
     */
    @RequestMapping("byJson.do")
    @ResponseBody
    public String byJson(@RequestBody People people){
        return people.toString();
    }

    /**
     * xml数据绑定
     * @param admin
     * @return
     */
    @RequestMapping("byXml.do")
    @ResponseBody
    public String byXml(@RequestBody Admin admin){
        return admin.toString();
    }
}
